<%@ page contentType="text/html; charset=utf-8" language="java"%>
<%@ include file="/common/index.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link type="text/css" rel="stylesheet" href="<%=basePath %>/css/index.css" />
<script language="javascript" src="<%=basePath %>/js/jquery-1.7.1.min.js"></script>
<script language="javascript" src="<%=basePath %>/js/lightbox/jquery.lightbox_me.js"></script>
<script language="javascript" src="<%=basePath %>/js/validate.js"></script>
</head>
<body>
<div class="show_main2">
          	
          	<s:form id="selectForm"  action='/manager/batchGame/selectGameCodeList.shtml' theme="simple">  
					<input type="hidden" name="batchCode"   value='<%=request.getAttribute("___batchCode") %>'   />
					<div class="right_main_padding_1">
					<!--
						<span class="spanTxt">礼包码：</span>
                      	<s:textfield  name="codeStr" theme="simple"  cssClass="inputText_1" maxlength= "20" /> 
	                	&nbsp;&nbsp;&nbsp;&nbsp;
	                    <span class="btn_1 searchBtn"  id="selectButton" onclick="selectData();" ></span>
	                 -->    
	                    <span style="display: none"> 
							gotoPage<s:textfield name="gotoPage" id="gotoPage" /> 
							pageSize<s:textfield name="pageSize" id="pageSize" /> 
							firstPage<s:textfield name="firstPage" id="firstPage" /> 
							lastPage<s:textfield name="lastPage" id="lastPage" />
							nextPage<s:textfield name="nextPage" id="nextPage" />
							prePage<s:textfield name="prePage" id="prePage" /> 
							countPage<s:textfield name="countPage" id="countPage" />
							countData<s:textfield name="countData" id="countData" />
						</span>
                </div>
			    </s:form>
                <table class="table_1" cellpadding="0" cellspacing="1">
                	<tr class="th_bg">
                	 	<td>游戏名</td>
                	 	<td>类型</td>
                	 	<td>礼包编码</td>
                	 	<td>礼包状态</td>
                    </tr>
                 <s:iterator value="gameCodeList" status="st">  
                 	<s:if test="#st.odd==true">
                 		<tr class="tr_1">
                 	</s:if>
                 	<s:else>
                 		<tr class="tr_2">
                 	</s:else>
                        <td><s:property value="gameName"/></td>
                        <td><s:if test="fuliType==1">激活码</s:if><s:elseif test="fuliType==2">礼包</s:elseif><s:elseif test="fuliType==3">道具</s:elseif><s:elseif test="fuliType==4">周边</s:elseif></td>
                        <td><s:property value="codeStr"/></td>
                        <td><s:if test="state==1">未领取</s:if><s:elseif test="state==2"><font color="blue">已领取</font></s:elseif></td>
                       <!-- 
                        <td><span class="shouxing" onclick="deleteVo('<s:property value="mid"/>')"> 删除</span>
                        </td>
                         -->
                 	</tr>
				 </s:iterator>                    
                </table>
                <div class="page_div">
                    共 <span id="allcount"><s:property value="countData"/></span> 条记录 &nbsp;	每页 <span id="pagesize" ><s:property value="pageSize"/></span> 条记录&nbsp;
					共 <span id="pagecount" ><s:property value="countPage"/></span> 页&nbsp;
					第 <span id="pageno" ><s:property value="gotoPage"/></span> 页&nbsp;&nbsp;
					<input type="button" class="wbt" value="首页" onclick="if(g('gotoPage').value!=g('firstPage').value){g('gotoPage').value=g('firstPage').value;selectData();}else{alert('已经在首页');}"/>
					&nbsp;
					<input type="button" class="wbt" value="上一页" onclick="if(g('gotoPage').value!=g('firstPage').value){g('gotoPage').value=g('prePage').value;selectData();}else{alert('已经在首页');}" />
					&nbsp;
					<input type="button" class="wbt" value="下一页" onclick="if(g('gotoPage').value != g('countPage').value){g('gotoPage').value=g('nextPage').value;selectData();}else{alert('已经在末页');}" />
					&nbsp;
					<input type="button" class="wbt" value="末页" onclick="if(g('gotoPage').value != g('lastPage').value){g('gotoPage').value=g('lastPage').value;selectData();}else{alert('已经在末页');}" />
					&nbsp;&nbsp;
                    
            	</div>
          	
          	
          	
</div>




<script language="javascript">

	$(function(){
		
		$('.close_but').live('click',function(){
			$(this).parent().remove();
		});
		
	})


	 function selectData()
	 {	
	 	$("#selectForm").submit();
	 }

	function toInsertDiv(){
		$("#SHOW_DIV_1").lightbox_me({
			 centered: false
			,modalCSS:{}
			,onClose:function(){clearFormValue('insert-update-Form');}
		});
		$('#insert-update-but').attr("onclick","insert();");
	}
	
	function insert(){

		if(!checkParas()){
			return;
		}

		var url = "<%=basePath %>/manager/app/insert.shtml";
		var param = $("#insert-update-Form").serialize();
		$.post(url 
			,param 
				,function(rs) {
					if(rs.code==0){
						selectData();
					}else{
						alert('操作失败');
					}
				}
		   ,'json');
		clearFormValue('insert-update-Form');
	}

	function toUpdateDiv(id){
		$("#SHOW_DIV_1").lightbox_me({
			centered: false
			,modalCSS:{top:'20px'}
			,onLoad:function(){
				var url = "<%=basePath %>/manager/app/selectVoById.shtml";
				var param = {id:id};
				$.post(url 
					,param 
						,function(rs) {
							if(rs.code==0){
								fillTemplateValue("insert-update-Form",rs.data);
							}
						}
				   ,'json');
			}
			,onClose:function(){clearFormValue('insert-update-Form');}
		});
	}
	

	function update(){
	
		if(!checkParas()){
			return;
		}
		
		var url = "<%=basePath %>/manager/app/update.shtml";
		var param = $("#insert-update-Form").serialize();
		$.post(url 
			,param 
				,function(rs) {
					if(rs.code==0){
						selectData();
					}
				}
		   ,'json');
		
		clearFormValue('insert-update-Form');
	}
	
	function checkParas(){
		if(document.getElementById("vo.appname").value==''){
			alert('请输入应用名称');	
			return false;
		}
		if(document.getElementById("vo.appid").value==''){
			alert('请输入应用id');	
			return false;
		}
		if(document.getElementById("vo.appkey").value==''){
			alert('请输入应用KEY');	
			return false;
		}
		if(document.getElementById("vo.appPlatform.pid").value=='' || document.getElementById("vo.appPlatform.pid").value=='0' ){
			alert('请输入第三方平台');	
			return false;
		}
		if(document.getElementById("vo.appOs.oid").value=='' || document.getElementById("vo.appOs.oid").value=='0' ){
			alert('请输入手机系统平台');	
			return false;
		}
		if(document.getElementById("vo.category").value=='' || document.getElementById("vo.category").value=='0'){
			alert('请输入应用类别');	
			return false;
		}
		if(document.getElementById("vo.categorylist").value=='' || document.getElementById("vo.categorylist").value=='0'){
			alert('请输入子分类明细');	
			return false;
		}
		if(document.getElementById("vo.appversion").value==''){
			alert('请输入应用版本');	
			return false;
		}
		if(document.getElementById("vo.appdesc").value==''){
			alert('请输入应用介绍');	
			return false;
		}
		if(document.getElementById("vo.author").value==''){
			alert('请输入应用提供方');	
			return false;
		}
		if(document.getElementById("vo.siteurl").value==''){
			alert('请输入网站URL');	
			return false;
		}
		return true;
	}
	
	function fillTemplateValue(boxId,json){
		var keys = new Array("mid","appname","appid","appkey","pid","oid","category","categorylist","appversion","appdesc","author","siteurl","status","appPlatform","appOs"); //这个要自定义
		for(var i=0;i<keys.length;i++){
			var e1 = $("#insert-update-Form [name*="+keys[i]+"]");
			if(e1.prop("nodeName")=="TEXTAREA"){
				e1.html(json[keys[i]]);
			}else if(e1.prop("nodeName")=="INPUT" || e1.prop("nodeName")=="SELECT" ){
				e1.val(json[keys[i]]);
			}
		}
		document.getElementById("vo.appid").value=json[keys[2]];
		document.getElementById("vo.appOs.oid").value=json['appOs_oid'];
		document.getElementById("vo.appPlatform.pid").value=json['appPlatform_pid'];
		document.getElementById("vo.category.cid").value=json['category_cid'];
		//生成子分类明细
		
		$('#insert-update-but').attr("onclick","update();");
	}

	function clearFormValue(fId){
		$('#'+fId)[0].reset();
	}
	
	function deleteVo(id){
		var url = "<%=basePath %>/manager/app/delete.shtml";
		var param = {id:id};
		$.post(url 
			,param 
				,function(rs) {
					if(rs.code==0){
						selectData();
					}
				}
		   ,'json');
	}
	


	function setCategoryList(obj){
		var j = $(document.getElementById("vo.categorylist"));
		if(obj.value!=0){
			var url = "<%=basePath %>/manager/category/getCategoryListByCid.shtml";
			var param = {id:obj.value};
			$.post(url 
				,param 
					,function(rs) {
						if(rs.code==0){
							var arrayStr = '';
							for(var i=0;i<rs.data.length;i++){
								arrayStr+="<option value='"+rs.data[i].clid+"'>"+rs.data[i].categorylist+"</option>";
							}
							j.html(arrayStr);
						}
					}
			   ,'json');
		}else{
			j.html('');
		}
	}
	
	
	function openPage(url){
		window.open(url,'newwindow','height=500,width=576,top=200,left=350,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no') ;
	}
	

</script>    
</body>
</html>
